import DataItemModel from "../../../cfw/mvc/DataItemModel";
import { FoodItemModelEnum } from "../../../public/GameEnumConfig";
import { ItemState } from "../../../cfw/tools/Define";
import User from "../../db/User";
import Player from "../../player/Player";
/**
* 食物
**/
export default class FoodItemModel extends DataItemModel {

	static CLASS_NAME: string = 'FoodItemModel'

	init(id, data) {
		super.init(id, data)
		this.setState(User.instance().getFoodItemState(this.ID))
	}
	// icon
	getIcon() {
		return 'texture/dininghall/' + this.data[FoodItemModelEnum.icon]
	}
	// 消费道具
	getCostItem() {
		return this.data[FoodItemModelEnum.costItem]
	}
	// 图标缩放
	getScale() {
		return this.data[FoodItemModelEnum.scale]
	}
	// 索引
	getIndex() {
		return this.data[FoodItemModelEnum.index]
	}
	// 饱和度
	getCleanNum() {
		return this.data[FoodItemModelEnum.cleanNum]
	}


	setState(s: number) {
		super.setState(s)
		User.instance().setFoodItemState(this.ID, s)
	}

	needBuy() {
		let list: number[] = this.getCostItem();
		return list.length > 0 && this.getState() != ItemState.GOT;
	}

	getOpenLevel() {
		let num = this.data[FoodItemModelEnum.adge]
		return num ? num : 0
	}
	isOpen() {
		return Player.instance().getLevel() >= this.getOpenLevel();
	}

}